'use strict';
import * as Koa from 'koa';
import { router, prefix } from '../middleware/router';
import { roleService } from '../service/role';
import { response } from '../middleware/result';

/** 角色api对象 */
@prefix('role')
class RoleController {
    /**
     * 
     * @api {POST} /role/create  角色新增
     * @apiDescription 角色新增
     * @apiName create
     * @apiParam (参数) {String} body  角色信息
     * @apiSampleRequest /role/create
     * @apiGroup role
     * @apiVersion 1.0.0
     */
    @router('/create',{method: 'post'})
    async create(ctx: Koa.Context) {
        let result = await roleService.create(ctx.request.body);
        response(ctx, result);
    }
    /**
     * 
     * @api {POST} /role/update  角色修改
     * @apiDescription 角色修改
     * @apiName update
     * @apiParam (参数) {String} body  角色信息
     * @apiSampleRequest /role/update
     * @apiGroup role
     * @apiVersion 1.0.0
     */
    @router('/update',{method: 'post'})
    async update(ctx: Koa.Context) {
        let doc= ctx.request.body;
        let result = await roleService.update(doc._id, doc);
        response(ctx, result);
    }
    /**
     * 
     * @api {GET} /role/delete/:id  删除角色
     * @apiDescription 删除角色
     * @apiName delete
     * @apiParam (参数) {String} id  角色id 
     * @apiSampleRequest /role/delete/:id
     * @apiGroup role
     * @apiVersion 1.0.0
     */
    @router('/delete/:id')
    async delete(ctx: Koa.Context) {
        let result = await roleService.delete(ctx.params.id);
        response(ctx, result);
    }
    /**
     * 
     * @api {GET} /role/queryById/:id  根据id获取角色信息
     * @apiDescription 根据id获取角色信息
     * @apiName queryById
     * @apiParam (参数) {String} id  角色id 
     * @apiSampleRequest /role/queryById/:id
     * @apiGroup role
     * @apiVersion 1.0.0
     */
    @router('/queryById/:id')
    async queryById(ctx: Koa.Context) {
        let result = await roleService.querybyId(ctx.params.id);
        response(ctx, result);
    }
    /**
     * 
     * @api {GET} /role/query  获取所有角色列表数据
     * @apiDescription 获取所有角色列表数据
     * @apiName query
     * @apiSampleRequest /role/query
     * @apiGroup role
     * @apiVersion 1.0.0
     */
    @router('/query')
    async query(ctx: Koa.Context){
        let result = await roleService.query();
        response(ctx, result);
    }
}